package org.jeese.modules.demo.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jeese.modules.demo.dao.BookDao;
import org.jeese.modules.demo.entity.Book;
import org.jeese.modules.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service("bookService")
public class BookServiceImpl implements BookService {
	@Autowired
	private BookDao bookDao;

	@Override
	public List<Book> listAll() {
		return bookDao.listAll();
	}

	@Override
	public PageInfo<Book> page(Integer pageNo, Integer pageSize) {
		PageHelper.startPage(pageNo, pageSize);
		List<Book> list = bookDao.listAll();
        return new PageInfo<Book>(list);
	}
	
	@Override
	public PageInfo<Book> page(Integer pageNo, Integer pageSize, String name) {
		PageHelper.startPage(pageNo, pageSize);
		List<Book> list = bookDao.listByName(name);
        return new PageInfo<Book>(list);
	}


	@Override
	public Map<String, Object> add(Book book) {
		Map<String, Object> map = new HashMap<String, Object>();
		int count = bookDao.add(book);
		map.put("code", 200);
		map.put("msg", "添加成功");
		map.put("count", count);
		return map;
		
	}

	@Override
	public Map<String, Object> edit(Book book) {
		Map<String, Object> map = new HashMap<String, Object>();
		int count = bookDao.edit(book);
		map.put("code", 200);
		map.put("msg", "修改成功");
		map.put("count", count);
		return map;
	}

	@Override
	public Map<String, Object> delete(Long id) {
		Map<String, Object> map = new HashMap<String, Object>();
		int count = bookDao.delete(id);
		map.put("code", 200);
		map.put("msg", "删除成功");
		map.put("count", count);
		return map;
	}

}
